package net.slidinglive.utilities.model;

import java.util.ArrayList;
import java.util.List;

import android.database.Cursor;
import android.provider.BaseColumns;
import android.provider.ContactsContract;

/**
 * @author Sebastian Hoffmann <bo.hoffi@gmail.com>
 */
public class Contact {

    private Integer id;
    private String displayName;
    private final List<PhoneNumber> phoneNumbers;
    private final List<EmailAddress> emailAddresses;
    private final List<Address> addresses;

    public Contact() {

        this.phoneNumbers = new ArrayList<PhoneNumber>();
        this.emailAddresses = new ArrayList<EmailAddress>();
        this.addresses = new ArrayList<Address>();
    }

    public Contact(final Cursor contactCursor) {

        this.phoneNumbers = new ArrayList<PhoneNumber>();
        this.emailAddresses = new ArrayList<EmailAddress>();
        this.addresses = new ArrayList<Address>();
        this.setId(contactCursor.getInt(contactCursor.getColumnIndex(BaseColumns._ID)));
        this.setDisplayName(contactCursor.getString(contactCursor
                .getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)));
    }

    public String toDebugString() {

        final StringBuilder output = new StringBuilder();
        output.append(BaseColumns._ID).append(": ").append(this.getId());
        output.append("\n");
        output.append(ContactsContract.Contacts.DISPLAY_NAME).append(": ").append(this.getDisplayName());

        return output.toString();
    }

    @Override
    public String toString() {

        final StringBuilder output = new StringBuilder();
        output.append(BaseColumns._ID).append(": ").append(this.getId());
        output.append("\n");
        output.append(ContactsContract.Contacts.DISPLAY_NAME).append(": ").append(this.getDisplayName());

        return output.toString();
    }

    /**
     * @return the id
     */
    public Integer getId() {

        return this.id;
    }

    /**
     * @param id
     *            the id to set
     */
    public void setId(int id) {

        this.id = id;
    }

    /**
     * @return the displayName
     */
    public String getDisplayName() {

        return this.displayName;
    }

    /**
     * @param displayName
     *            the displayName to set
     */
    public void setDisplayName(String displayName) {

        this.displayName = displayName;
    }

    /**
     * @return the numbers
     */
    public List<PhoneNumber> getPhoneNumbers() {

        return this.phoneNumbers;
    }

    /**
     * @return the emailAddresses
     */
    public List<EmailAddress> getEmailAddresses() {

        return this.emailAddresses;
    }

    /**
     * @return the addresses
     */
    public List<Address> getAddresses() {

        return this.addresses;
    }

    public void addPhoneNumber(final PhoneNumber number) {

        this.phoneNumbers.add(number);
    }

    public void addEmailAddress(final EmailAddress emailAddress) {

        this.emailAddresses.add(emailAddress);
    }

    public void addAddress(final Address address) {

        this.addresses.add(address);
    }
}